# // ***************************************************************************
# // 
# // Copyright (c) Scriptimus Ex Machina.  All rights reserved.
# // 
# // Microsoft Deployment Toolkit Support Script
# //
# // File:      Reset-AdministratorPassword.ps1
# // 
# // Version:   1.00 
# // 
# // Purpose:   Resets the local Administrators password
# // 
# // ***************************************************************************

<#
.Synopsis
   Reset Local Admin Password
.DESCRIPTION
   This script uses ADSI to change the Local Admin user password. Only administrators can change the local administrator password.

.EXAMPLE
   Reset-AdministratorPassword.ps1 -Password Pasword01
#>

    [CmdletBinding()]

    [OutputType([int])]

    Param (

        # Parameter for the new password

        [Parameter(Mandatory=$true,
                   ValueFromPipelineByPropertyName=$true,
                   Position=0)]

        [String]$Password

    )

    Begin{

        Write-Host "Begining script"

        function ConvertFrom-Base64($string) {

            $bytes  = [System.Convert]::FromBase64String($string);

            $decoded = [System.Text.Encoding]::UTF8.GetString($bytes); 

            return $decoded;

            }
        }

    Process{

        Write-Host "Processing Script"

        $DecryptedPassword = (ConvertFrom-Base64 $Password)


        [ADSI]$Admin="WinNT://$Env:COMPUTERNAME/Administrator,user"

        Write-Host "Resetting local administrator password."
        $Admin.SetPassword("$DecryptedPassword")

    }

    End{

        Write-Host "End Script"

        }
